package com.holystone.orca.sys.service.impl;

import java.util.Map;



//import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.holystone.orca.base.service.impl.BaseServiceImpl;
import com.holystone.orca.common.PageData;
import com.holystone.orca.sys.mybatis.dao.SysOperationLogMapper;
import com.holystone.orca.sys.mybatis.model.SysOperationLog;
import com.holystone.orca.sys.service.ISysOperationLogService;
@Service("sysOperationLogService")
public class SysOperationLogServiceImpl extends BaseServiceImpl<SysOperationLog> implements ISysOperationLogService{
	//private static Logger logger = Logger.getLogger(SysOperationLogServiceImpl.class);
	
	/**dao层服务*/
	@Autowired
	private SysOperationLogMapper sysOperationLogMapper;
	
	@Override
	public PageData pagingSysOperationLog(int iPageNo, int iPageSize,
			String orderField, Map<String, Object> map) throws Exception {
		 	PageHelper.startPage(iPageNo, iPageSize);
	        PageInfo<SysOperationLog> pageInfo = new PageInfo<SysOperationLog>(sysOperationLogMapper.getOperationLog(map));
			PageData pageData =  new PageData();
			pageData.setPageList(pageInfo.getList());
			pageData.setTotalCount(pageInfo.getTotal());
			pageData.setPageSize(pageInfo.getPageSize());
			pageData.setPageNo(pageInfo.getPageNum());
			pageData.setTotalPage(pageInfo.getPages());
			return pageData;
	}

	@Override
	public boolean addOperationLog(String personCode,String requestIp,String operation,String sessionId,String information)
			throws Exception {
		SysOperationLog sysOperationLog = new SysOperationLog();
		sysOperationLog.setInformation(information);
		sysOperationLog.setOperation(operation);
		sysOperationLog.setSessionId(sessionId);
		sysOperationLog.setRequestIp(requestIp);
		sysOperationLog.setPersonCode(personCode);
		int result = sysOperationLogMapper.addOperationLog(sysOperationLog);
		if(result == 1){
			//如果日志的条数大于1000条，则删除最早插入的数据
			sysOperationLogMapper.delMoreLog();
			return true;
		}else{
			return false;
		}
	}
	
	
}
